/**
 * 
 */
package org.rollinitiative.d20web.charactersheet.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author jmccormi
 *
 */
public class SavesView extends Composite
{
//    private final FlexTable savesTable_ = new FlexTable();
    private final Grid savesTable_ = new Grid(4,2);
    private final TextBox conditionalMods_ = new TextBox();
    
    
    public SavesView()
    {    	
        // Setup the table
        savesTable_.setCellSpacing(1);
        savesTable_.setCellPadding(1);
        savesTable_.setWidth("50%");
        
        conditionalMods_.setText("No conditional modifiers");
        
        VerticalPanel panel = new VerticalPanel();
    	panel.setSpacing(2);
        panel.add(savesTable_);
        panel.add(conditionalMods_);

        // Hook up events.

        initWidget(panel);
        initSavesTable(); 
    }
    
    private void initSavesTable()
    {
        
        // Create the header row.
        savesTable_.setText(0, 0, "Save");
        savesTable_.setText(0, 1, "Score");
        
     // Create content rows
        savesTable_.setText(1, 0, "Fortitude");
        savesTable_.setText(1, 1, "+0");
        savesTable_.setText(2, 0, "Reflex");
        savesTable_.setText(2, 1, "+0");
        savesTable_.setText(3, 0, "Will");
        savesTable_.setText(3, 1, "+0");
    }

	public void setCharacter(SavesData saves) {
		savesTable_.setText(1, 1, modifier(saves.getFortitude()));
		savesTable_.setText(2, 1, modifier(saves.getReflex()));
		savesTable_.setText(3, 1, modifier(saves.getWill()));
	}
	
	public String modifier(int modifier) {
		if (modifier > -1) {
			return "+" + modifier;
		}
		else {
//			return "-" + modifier;
		    return "";
		}
	}
}
